home *** CD-ROM | disk | FTP | other *** search
/ CyberMycha 2005 May / CyberMycha 05-2005 (Poland).bin / Immortal / cotndemo.exe / Data1.cab / combinewithshadowmap.psh < prev    next >
Encoding:
Text File  |  2004-11-16  |  1.5 KB  |  41 lines

  1. // pixel shader to combine shadow map texture with model drawing to create shadows
  2. // used when drawing terrain
  3.  
  4. ps_2_0                // version
  5. dcl t0.xyzw            // lookup object texel using this coordinate
  6. dcl t1.xyzw            // lookup texel on shadowmap using this coordinate
  7. dcl v0.rgba            // input color
  8. dcl_2d s0            // object texture
  9. dcl_2d s1            // shadow map texture
  10.  
  11. // sample center point and three other nearby points and average the results
  12. def c0,     0.00087891,     0,                0,0        // point 2
  13. def c1,    -0.00043945,     0.00076116,    0,0        // point 3
  14. def c2,    -0.00043945,    -0.00076116,    0,0        // point 4
  15. def c3,     0.25,0.25,0.25,0.25            // factor to divide by 4
  16. // c16 defined by app:  1-shadowalpha, 1.0f, zbias, unused
  17.  
  18. add r1,t1,c0
  19. add r2,t1,c1
  20. add r3,t1,c2
  21.  
  22. texld r0, t1, s1    // get point 1 from shadow map
  23. texld r1, r1, s1    // get point 2 from shadow map
  24. texld r2, r2, s1    // get point 3 from shadow map
  25. texld r3, r3, s1    // get point 4 from shadow map
  26.  
  27. mov r4.r,t1.z        // terrain doesn't need zbias since it isn't generating shadow
  28.  
  29. sub r0.r,r0.r,r4.r    
  30. sub r0.g,r1.r,r4.r
  31. sub r0.b,r2.r,r4.r
  32. sub r0.a,r3.r,r4.r
  33. cmp r5,r0,c16.y,c16.x  // r5 = results of the comparisons with all the points
  34. dp4 r6,r5,c3        // average the result
  35. mov r6.a,c16.y        // shadow alpha = 1.0 (ie shadow doesn't reduce alpha)
  36.  
  37. texld r0, t0, s0    // get the texel from the object texture
  38. mul r0,r0,v0        // combine with input color
  39. mul r0,r0,r6        // combine with shadow
  40. mov oC0,r0            // move resulting color to output
  41.